<template>
	<view class="content">
		<div class="login-top cl" v-if="if_login">
			<image src="https://kehu-1256834579.cos.ap-shanghai.myqcloud.com/weier/login_top.png"></image>
			<div class="photo-round">
				<image src="https://kehu-1256834579.cos.ap-shanghai.myqcloud.com/weier/logo.png?1" @tap="param_to_url('profile')"></image>
				<div class="logo-right cl">
					<p @tap="param_to_url('profile')">{{member_profile.nickName}}</p>
					<p>{{member_profile.mobile}}</p>
					<p @tap="param_to_url('renzheng')">未认证</p>
				</div>
				<span class="iconfont icon-you"></span>
			</div>
			
		</div>
		<div class="login-top cl" v-else>
			<image src="https://kehu-1256834579.cos.ap-shanghai.myqcloud.com/weier/login_top.png"></image>
			<div class="photo-round" @tap="param_to_url('login')">
				<image src="https://kehu-1256834579.cos.ap-shanghai.myqcloud.com/weier/logo.png"></image>
				<div class="logo-right cl">
					<p >未登录</p>
					<p>点击立即登录</p>
					<p>未认证</p>
				</div>
				<span class="iconfont icon-you"></span>
			</div>
			
		</div>
		<ul class="order-list cl">
			<li @tap="param_to_url('order')">
				<image src="https://kehu-1256834579.cos.ap-shanghai.myqcloud.com/weier/dingdan.png"></image>
				<p>全部订单</p>
			</li>
			<li @tap="param_to_url('order')">
				<image src="https://kehu-1256834579.cos.ap-shanghai.myqcloud.com/weier/daizhifu.png"></image>
				<p>待支付</p>
			</li>
			<li @tap="param_to_url('order')">
				<image src="https://kehu-1256834579.cos.ap-shanghai.myqcloud.com/weier/jinxingzhong.png"></image>
				<p>进行中</p>
			</li>
			<li @tap="param_to_url('order')">
				<image src="https://kehu-1256834579.cos.ap-shanghai.myqcloud.com/weier/yiwancheng.png"></image>
				<p>已完成</p>
			</li>
		</ul>
		<div class="order-list order-list2 cl" style="margin-top: 50rpx;">
			<p style="margin-left: 3%;">我的钱包</p>
			<ul style="margin-top: 30rpx;" v-if="if_login">
				<li @tap="param_to_url('qianbao?type=1')">
					<p><span>{{member_profile.yue ? member_profile.yue : '0.00'}}</span>元</p>
					<p>余额></p>
				</li>
				<li @tap="param_to_url('qianbao?type=2')">
					<p><span>{{member_profile.yajin}}</span>元</p>
					<p>押金></p>
				</li>
				<li @tap="param_to_url('coupon')">
					<p><span>0</span>张</p>
					<p>优惠券></p>
				</li>
			</ul>
			<ul style="margin-top: 30rpx;" v-else>
				<li @tap="param_to_url('qianbao?type=1')">
					<p><span>0.00</span>元</p>
					<p>余额></p>
				</li>
				<li @tap="param_to_url('qianbao?type=2')">
					<p><span>0.00</span>元</p>
					<p>押金></p>
				</li>
				<li @tap="param_to_url('coupon')">
					<p><span>0</span>张</p>
					<p>优惠券></p>
				</li>
			</ul>
		</div>
		<div class="order-list cl" style="margin-top: 50rpx;">
			<p style="margin-left: 3%;">更多功能</p>
			<ul style="margin-top: 30rpx;">
				<li>
					<image src="https://kehu-1256834579.cos.ap-shanghai.myqcloud.com/weier/kefu.png?2"></image>
					<p>客服中心</p>
					  <button open-type="contact" class="contact-btn" style="opacity: 0;"></button>
				</li>
				<li @tap="param_to_url('feedback')">
					<image src="https://kehu-1256834579.cos.ap-shanghai.myqcloud.com/weier/guzhang.png?2"></image>
					<p>故障反馈</p>
				</li>
			</ul>
		</div>
	</view>
</template>

<script>
	import common_config from '../../static/js/common.js';
	var config = common_config.config;
	var that;	
	var userInfo;
	export default {
		data() {
			return {
				if_login:false,
				member_profile:{}
			}
		},
		onShow(options) {
			that = this;
			that.plusReady();
		},
		methods: {
			//初始化
			plusReady(){
				userInfo = uni.getStorageSync('userInfo');
				if(userInfo){
					userInfo = JSON.parse(userInfo);
					that.if_login = true;
					that.member_profile = userInfo;
					that.load_row_id();
				}else{
					that.if_login = false;
				}
				
			},	
			
			param_to_url(url){
				if(!that.if_login && url != 'login'){
					url = 'login';
				}
				uni.navigateTo({
					url:url
				})
			},
			load_row_id(){
				uni.request({
				  url: config.request_url+'/v2/open/worksheet/getFilterRows',
				  method: 'POST',
				  header: {
					'Content-Type': 'application/json'
				  },
				  data: {
					"appKey": config.appKey,
					"sign": config.sign,
					"worksheetId": "yhgl",
					"pageSize": 50,
					"pageIndex": 1,
					"filters": [
						{
							"controlId": "openid",
							"dataType": 2,
							"spliceType": 1,
							"filterType": 2,
							"value": userInfo.openid //传openid
						}
					]
				  },
				  success: (res) => {
					console.log('返回结果:', res.data);
					res = res.data;
					console.log(res);
					if(res.success){
						var datas = res.data.rows;
						for(var i = 0;i < datas.length;i++){
							if(datas[i].openid == userInfo.openid){
								
								var member_profile = {
									openid:datas[i].openid,
									nickName:datas[i].nicheng,
									photo:'',
									rowid:datas[i].rowid,
									mobile:datas[i].shoujihao,
									xinyongfen:datas[i].xinyongfen,
									yajin:datas[i].yajin,
									sfsx:datas[i].sfsx,
								};
								uni.setStorageSync('userInfo',JSON.stringify(member_profile));
								that.member_profile = member_profile;
						
							}
						}
					}else{
						 uni.showToast({ title: res.data.msg || '数据获取失败', icon: 'none' });
					}
				  },
				  fail: (err) => {
					console.error('请求失败:', err);
					uni.showToast({ title: '网络错误', icon: 'none' });
				  }
				})  
			}
		}
	}
</script>

<style>
page,.content{background-color: #f6f6f6;}
.login-top{height: 408rpx;width: 100%;position: relative;padding-bottom: 80rpx;}
.login-top > image{width: 100%;height: 408rpx;position: absolute;}
.login-top .photo-round{width: 88%;margin-left: 3%;background-color: #fff;border-radius: 16rpx;padding: 20rpx 3%;position: relative;margin-top: 260rpx;height: 134rpx;}
.photo-round image{float: left;width: 180rpx;height: 180rpx;border-radius: 100%;border: 2px solid #fff;margin-top: -60rpx;}
.photo-round .logo-right{float: left;margin-left: 20rpx;float: left;}
.photo-round .logo-right p:nth-child(1){font-weight: bold;}
.photo-round .logo-right p:nth-child(2){font-size: 24rpx;color: #6C675E;margin-top: 8rpx;}
.photo-round .logo-right p:nth-child(3){display: block;color: #fff;background-color: #68C8FF;font-size: 24rpx;padding: 4rpx 0px;width: 100rpx;text-align: center;border-radius: 16rpx;margin-top: 8rpx;}
.login-top .icon-you{position: absolute;right: 3%;top: 58rpx;font-size: 48rpx;z-index: 10;}
.order-list{width: 94%;margin-left: 3%;position: relative;background-color: #fff;margin-top: 0rpx;border-radius: 16rpx;padding: 20rpx 0px;}
.order-list li{float: left;width: 25%;text-align: center;position: relative;}
.order-list li image{width: 35%;height: 61rpx;}
.order-list li p{font-size: 28rpx;}
.order-list > p{font-weight: bold;font-size: 28rpx;}
.order-list2 ul li{font-weight: bold;width: 33.33%;}
.order-list2 ul li p{font-size: 24rpx;}
.order-list2 ul li p span{font-size: 32rpx;}
.contact-btn {position: absolute; top: 0; left: 0; width: 100%; height: 100%; background: transparent; border: none; padding: 0; margin: 0;}
</style>
